from flask import Flask, render_template
from flask_sqlalchemy import SQLAlchemy
import os

app = Flask(__name__)
#  mysql+pymysql://<username>:<password>@<host>/<dbname>[?<options>]
app.config["SQLALCHEMY_DATABASE_URI"] = "mysql+pymysql://root:396977Qq@120.24.241.188:3306/movie"
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = True
app.config['UP_DIR'] = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'static/media/')
app.config['USER_IMAGE'] = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'static/users/')  # 存放用户头像的路径
app.config["SECRET_KEY"] = 'af2fad8cfe1f4c5fac4aa5edf6fcc8f3'
app.debug = True
db =SQLAlchemy(app)

from app.admin import admin as admin_blueprint
from app.home import home as home_blueprint

app.register_blueprint(admin_blueprint, url_prefix="/admin")
app.register_blueprint(home_blueprint)  # 这里url可以不写

# 添加全局404页面
@app.errorhandler(404)
def page_not_found(error):
    return render_template('404.html'), 404

# 添加全局401无权限页面
@app.errorhandler(401)
def unauthorized_access(error):
    return render_template('admin/401.html'), 401
